{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "/* 本电子讲义使用之CSS */\n",
       "div.code_cell {\n",
       "    background-color: #e5f1fe;\n",
       "}\n",
       "div.cell.selected {\n",
       "    background-color: #effee2;\n",
       "    font-size: 2rem;\n",
       "    line-height: 2.4rem;\n",
       "}\n",
       "div.cell.selected .rendered_html table {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html pre code {\n",
       "    background-color: #C4E4ff;   \n",
       "    padding: 2px 25px;\n",
       "}\n",
       ".rendered_html pre {\n",
       "    background-color: #99c9ff;\n",
       "}\n",
       "div.code_cell .CodeMirror {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html img, .rendered_html svg {\n",
       "    max-width: 50%;\n",
       "    height: auto;\n",
       "    float: center;\n",
       "}\n",
       "/* Gradient transparent - color - transparent */\n",
       "hr {\n",
       "    border: 0;\n",
       "    border-bottom: 1px dashed #ccc;\n",
       "}\n",
       ".emoticon{\n",
       "    font-size: 5rem;\n",
       "    line-height: 4.4rem;\n",
       "    text-align: center;\n",
       "    vertical-align: middle;\n",
       "}\n",
       "\n",
       "</style>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%html\n",
    "<style>\n",
    "/* 本电子讲义使用之CSS */\n",
    "div.code_cell {\n",
    "    background-color: #e5f1fe;\n",
    "}\n",
    "div.cell.selected {\n",
    "    background-color: #effee2;\n",
    "    font-size: 2rem;\n",
    "    line-height: 2.4rem;\n",
    "}\n",
    "div.cell.selected .rendered_html table {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html pre code {\n",
    "    background-color: #C4E4ff;   \n",
    "    padding: 2px 25px;\n",
    "}\n",
    ".rendered_html pre {\n",
    "    background-color: #99c9ff;\n",
    "}\n",
    "div.code_cell .CodeMirror {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html img, .rendered_html svg {\n",
    "    max-width: 50%;\n",
    "    height: auto;\n",
    "    float: center;\n",
    "}\n",
    "/* Gradient transparent - color - transparent */\n",
    "hr {\n",
    "    border: 0;\n",
    "    border-bottom: 1px dashed #ccc;\n",
    "}\n",
    ".emoticon{\n",
    "    font-size: 5rem;\n",
    "    line-height: 4.4rem;\n",
    "    text-align: center;\n",
    "    vertical-align: middle;\n",
    "}\n",
    "\n",
    "</style>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 回顾人脸（人脸识别数据扩展）\n",
    "\n",
    "* 我们先回顾上节课的基本内容，并获取到图片的基本数据，学会使用  [jsonviewer.stack.hu(json转换检查数据)](http://jsonviewer.stack.hu)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 快速回顾上节：面部检测（易）\n",
    "\n",
    "* Azure face API 面部检测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'[{\"faceId\": \"117c7959-4749-4edc-a730-8b02c0601d30\", \"faceRectangle\": {\"top\": 118, \"left\": 144, \"width\": 88, \"height\": 88}, \"faceAttributes\": {\"smile\": 0.813, \"headPose\": {\"pitch\": -3.4, \"roll\": 1.4, \"yaw\": 9.4}, \"gender\": \"male\", \"age\": 18.0, \"facialHair\": {\"moustache\": 0.1, \"beard\": 0.1, \"sideburns\": 0.1}, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.003, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 0.813, \"neutral\": 0.184, \"sadness\": 0.0, \"surprise\": 0.0}, \"blur\": {\"blurLevel\": \"low\", \"value\": 0.21}, \"exposure\": {\"exposureLevel\": \"overExposure\", \"value\": 0.81}, \"noise\": {\"noiseLevel\": \"low\", \"value\": 0.01}, \"makeup\": {\"eyeMakeup\": false, \"lipMakeup\": false}, \"accessories\": [], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.18, \"invisible\": false, \"hairColor\": [{\"color\": \"brown\", \"confidence\": 0.95}, {\"color\": \"black\", \"confidence\": 0.93}, {\"color\": \"other\", \"confidence\": 0.23}, {\"color\": \"blond\", \"confidence\": 0.23}, {\"color\": \"gray\", \"confidence\": 0.21}, {\"color\": \"red\", \"confidence\": 0.15}]}}}, {\"faceId\": \"6bed9231-c27b-4f46-be23-6f298235f525\", \"faceRectangle\": {\"top\": 117, \"left\": 376, \"width\": 64, \"height\": 64}, \"faceAttributes\": {\"smile\": 0.456, \"headPose\": {\"pitch\": -1.1, \"roll\": -0.2, \"yaw\": 6.6}, \"gender\": \"female\", \"age\": 20.0, \"facialHair\": {\"moustache\": 0.0, \"beard\": 0.0, \"sideburns\": 0.0}, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.001, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 0.456, \"neutral\": 0.542, \"sadness\": 0.001, \"surprise\": 0.0}, \"blur\": {\"blurLevel\": \"low\", \"value\": 0.16}, \"exposure\": {\"exposureLevel\": \"goodExposure\", \"value\": 0.58}, \"noise\": {\"noiseLevel\": \"low\", \"value\": 0.01}, \"makeup\": {\"eyeMakeup\": false, \"lipMakeup\": true}, \"accessories\": [], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.08, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 1.0}, {\"color\": \"other\", \"confidence\": 0.63}, {\"color\": \"brown\", \"confidence\": 0.46}, {\"color\": \"gray\", \"confidence\": 0.39}, {\"color\": \"blond\", \"confidence\": 0.03}, {\"color\": \"red\", \"confidence\": 0.01}]}}}, {\"faceId\": \"8693aea4-c385-499a-89e2-2d19a0c30a23\", \"faceRectangle\": {\"top\": 41, \"left\": 676, \"width\": 52, \"height\": 52}, \"faceAttributes\": {\"smile\": 1.0, \"headPose\": {\"pitch\": 3.0, \"roll\": -1.3, \"yaw\": -0.6}, \"gender\": \"male\", \"age\": 23.0, \"facialHair\": {\"moustache\": 0.1, \"beard\": 0.1, \"sideburns\": 0.1}, \"glasses\": \"ReadingGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 1.0, \"neutral\": 0.0, \"sadness\": 0.0, \"surprise\": 0.0}, \"blur\": {\"blurLevel\": \"low\", \"value\": 0.0}, \"exposure\": {\"exposureLevel\": \"goodExposure\", \"value\": 0.66}, \"noise\": {\"noiseLevel\": \"low\", \"value\": 0.07}, \"makeup\": {\"eyeMakeup\": false, \"lipMakeup\": false}, \"accessories\": [{\"type\": \"glasses\", \"confidence\": 1.0}], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.06, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 0.98}, {\"color\": \"brown\", \"confidence\": 0.96}, {\"color\": \"other\", \"confidence\": 0.22}, {\"color\": \"gray\", \"confidence\": 0.21}, {\"color\": \"red\", \"confidence\": 0.09}, {\"color\": \"blond\", \"confidence\": 0.08}]}}}, {\"faceId\": \"de8d7f6a-6b67-4a66-bc7c-ae6de435b612\", \"faceRectangle\": {\"top\": 69, \"left\": 445, \"width\": 52, \"height\": 52}, \"faceAttributes\": {\"smile\": 1.0, \"headPose\": {\"pitch\": 0.2, \"roll\": 2.6, \"yaw\": 1.5}, \"gender\": \"female\", \"age\": 21.0, \"facialHair\": {\"moustache\": 0.0, \"beard\": 0.0, \"sideburns\": 0.0}, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 1.0, \"neutral\": 0.0, \"sadness\": 0.0, \"surprise\": 0.0}, \"blur\": {\"blurLevel\": \"low\", \"value\": 0.0}, \"exposure\": {\"exposureLevel\": \"goodExposure\", \"value\": 0.56}, \"noise\": {\"noiseLevel\": \"medium\", \"value\": 0.33}, \"makeup\": {\"eyeMakeup\": false, \"lipMakeup\": false}, \"accessories\": [], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.11, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 1.0}, {\"color\": \"brown\", \"confidence\": 0.81}, {\"color\": \"other\", \"confidence\": 0.41}, {\"color\": \"gray\", \"confidence\": 0.37}, {\"color\": \"blond\", \"confidence\": 0.03}, {\"color\": \"red\", \"confidence\": 0.02}]}}}, {\"faceId\": \"2bffa3fd-ecf6-4dcc-8686-23301e0508b6\", \"faceRectangle\": {\"top\": 95, \"left\": 238, \"width\": 51, \"height\": 51}, \"faceAttributes\": {\"smile\": 0.981, \"headPose\": {\"pitch\": 7.2, \"roll\": 1.2, \"yaw\": 2.6}, \"gender\": \"female\", \"age\": 17.0, \"facialHair\": {\"moustache\": 0.0, \"beard\": 0.0, \"sideburns\": 0.0}, \"glasses\": \"ReadingGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 0.981, \"neutral\": 0.019, \"sadness\": 0.0, \"surprise\": 0.0}, \"blur\": {\"blurLevel\": \"low\", \"value\": 0.07}, \"exposure\": {\"exposureLevel\": \"goodExposure\", \"value\": 0.69}, \"noise\": {\"noiseLevel\": \"medium\", \"value\": 0.48}, \"makeup\": {\"eyeMakeup\": false, \"lipMakeup\": false}, \"accessories\": [{\"type\": \"glasses\", \"confidence\": 1.0}], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.11, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 0.98}, {\"color\": \"brown\", \"confidence\": 0.86}, {\"color\": \"other\", \"confidence\": 0.4}, {\"color\": \"gray\", \"confidence\": 0.36}, {\"color\": \"blond\", \"confidence\": 0.09}, {\"color\": \"red\", \"confidence\": 0.08}]}}}, {\"faceId\": \"b5a606b9-82dd-40b0-9180-cc7c36b0d575\", \"faceRectangle\": {\"top\": 94, \"left\": 540, \"width\": 48, \"height\": 48}, \"faceAttributes\": {\"smile\": 1.0, \"headPose\": {\"pitch\": -7.7, \"roll\": 5.0, \"yaw\": 6.9}, \"gender\": \"female\", \"age\": 19.0, \"facialHair\": {\"moustache\": 0.0, \"beard\": 0.0, \"sideburns\": 0.0}, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 1.0, \"neutral\": 0.0, \"sadness\": 0.0, \"surprise\": 0.0}, \"blur\": {\"blurLevel\": \"low\", \"value\": 0.08}, \"exposure\": {\"exposureLevel\": \"goodExposure\", \"value\": 0.65}, \"noise\": {\"noiseLevel\": \"low\", \"value\": 0.08}, \"makeup\": {\"eyeMakeup\": false, \"lipMakeup\": false}, \"accessories\": [], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.1, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 1.0}, {\"color\": \"brown\", \"confidence\": 0.88}, {\"color\": \"other\", \"confidence\": 0.35}, {\"color\": \"gray\", \"confidence\": 0.33}, {\"color\": \"blond\", \"confidence\": 0.05}, {\"color\": \"red\", \"confidence\": 0.04}]}}}]'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "\n",
    "# set to your own subscription key value\n",
    "subscription_key = \"aae352f75f71488983b4031443382905\"\n",
    "assert subscription_key\n",
    "\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "json.dumps(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '117c7959-4749-4edc-a730-8b02c0601d30',\n",
       "  'faceRectangle': {'top': 118, 'left': 144, 'width': 88, 'height': 88},\n",
       "  'faceAttributes': {'smile': 0.813,\n",
       "   'headPose': {'pitch': -3.4, 'roll': 1.4, 'yaw': 9.4},\n",
       "   'gender': 'male',\n",
       "   'age': 18.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.003,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.813,\n",
       "    'neutral': 0.184,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.21},\n",
       "   'exposure': {'exposureLevel': 'overExposure', 'value': 0.81},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.01},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.18,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.95},\n",
       "     {'color': 'black', 'confidence': 0.93},\n",
       "     {'color': 'other', 'confidence': 0.23},\n",
       "     {'color': 'blond', 'confidence': 0.23},\n",
       "     {'color': 'gray', 'confidence': 0.21},\n",
       "     {'color': 'red', 'confidence': 0.15}]}}},\n",
       " {'faceId': '6bed9231-c27b-4f46-be23-6f298235f525',\n",
       "  'faceRectangle': {'top': 117, 'left': 376, 'width': 64, 'height': 64},\n",
       "  'faceAttributes': {'smile': 0.456,\n",
       "   'headPose': {'pitch': -1.1, 'roll': -0.2, 'yaw': 6.6},\n",
       "   'gender': 'female',\n",
       "   'age': 20.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.001,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.456,\n",
       "    'neutral': 0.542,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.16},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.58},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.01},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.08,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'other', 'confidence': 0.63},\n",
       "     {'color': 'brown', 'confidence': 0.46},\n",
       "     {'color': 'gray', 'confidence': 0.39},\n",
       "     {'color': 'blond', 'confidence': 0.03},\n",
       "     {'color': 'red', 'confidence': 0.01}]}}},\n",
       " {'faceId': '8693aea4-c385-499a-89e2-2d19a0c30a23',\n",
       "  'faceRectangle': {'top': 41, 'left': 676, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': 3.0, 'roll': -1.3, 'yaw': -0.6},\n",
       "   'gender': 'male',\n",
       "   'age': 23.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.66},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.07},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.06,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.96},\n",
       "     {'color': 'other', 'confidence': 0.22},\n",
       "     {'color': 'gray', 'confidence': 0.21},\n",
       "     {'color': 'red', 'confidence': 0.09},\n",
       "     {'color': 'blond', 'confidence': 0.08}]}}},\n",
       " {'faceId': 'de8d7f6a-6b67-4a66-bc7c-ae6de435b612',\n",
       "  'faceRectangle': {'top': 69, 'left': 445, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': 0.2, 'roll': 2.6, 'yaw': 1.5},\n",
       "   'gender': 'female',\n",
       "   'age': 21.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.56},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.33},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.11,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.81},\n",
       "     {'color': 'other', 'confidence': 0.41},\n",
       "     {'color': 'gray', 'confidence': 0.37},\n",
       "     {'color': 'blond', 'confidence': 0.03},\n",
       "     {'color': 'red', 'confidence': 0.02}]}}},\n",
       " {'faceId': '2bffa3fd-ecf6-4dcc-8686-23301e0508b6',\n",
       "  'faceRectangle': {'top': 95, 'left': 238, 'width': 51, 'height': 51},\n",
       "  'faceAttributes': {'smile': 0.981,\n",
       "   'headPose': {'pitch': 7.2, 'roll': 1.2, 'yaw': 2.6},\n",
       "   'gender': 'female',\n",
       "   'age': 17.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.981,\n",
       "    'neutral': 0.019,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.07},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.69},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.48},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.11,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.86},\n",
       "     {'color': 'other', 'confidence': 0.4},\n",
       "     {'color': 'gray', 'confidence': 0.36},\n",
       "     {'color': 'blond', 'confidence': 0.09},\n",
       "     {'color': 'red', 'confidence': 0.08}]}}},\n",
       " {'faceId': 'b5a606b9-82dd-40b0-9180-cc7c36b0d575',\n",
       "  'faceRectangle': {'top': 94, 'left': 540, 'width': 48, 'height': 48},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': -7.7, 'roll': 5.0, 'yaw': 6.9},\n",
       "   'gender': 'female',\n",
       "   'age': 19.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.08},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.08},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.1,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.88},\n",
       "     {'color': 'other', 'confidence': 0.35},\n",
       "     {'color': 'gray', 'confidence': 0.33},\n",
       "     {'color': 'blond', 'confidence': 0.05},\n",
       "     {'color': 'red', 'confidence': 0.04}]}}}]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = response.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.json_normalize(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['117c7959-4749-4edc-a730-8b02c0601d30'\n",
      " '6bed9231-c27b-4f46-be23-6f298235f525'\n",
      " '8693aea4-c385-499a-89e2-2d19a0c30a23'\n",
      " 'de8d7f6a-6b67-4a66-bc7c-ae6de435b612'\n",
      " '2bffa3fd-ecf6-4dcc-8686-23301e0508b6'\n",
      " 'b5a606b9-82dd-40b0-9180-cc7c36b0d575']\n"
     ]
    }
   ],
   "source": [
    "print(df[\"faceId\"].values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['faceId', 'faceRectangle.top', 'faceRectangle.left',\n",
       "       'faceRectangle.width', 'faceRectangle.height', 'faceAttributes.smile',\n",
       "       'faceAttributes.headPose.pitch', 'faceAttributes.headPose.roll',\n",
       "       'faceAttributes.headPose.yaw', 'faceAttributes.gender',\n",
       "       'faceAttributes.age', 'faceAttributes.facialHair.moustache',\n",
       "       'faceAttributes.facialHair.beard',\n",
       "       'faceAttributes.facialHair.sideburns', 'faceAttributes.glasses',\n",
       "       'faceAttributes.emotion.anger', 'faceAttributes.emotion.contempt',\n",
       "       'faceAttributes.emotion.disgust', 'faceAttributes.emotion.fear',\n",
       "       'faceAttributes.emotion.happiness', 'faceAttributes.emotion.neutral',\n",
       "       'faceAttributes.emotion.sadness', 'faceAttributes.emotion.surprise',\n",
       "       'faceAttributes.blur.blurLevel', 'faceAttributes.blur.value',\n",
       "       'faceAttributes.exposure.exposureLevel',\n",
       "       'faceAttributes.exposure.value', 'faceAttributes.noise.noiseLevel',\n",
       "       'faceAttributes.noise.value', 'faceAttributes.makeup.eyeMakeup',\n",
       "       'faceAttributes.makeup.lipMakeup', 'faceAttributes.accessories',\n",
       "       'faceAttributes.occlusion.foreheadOccluded',\n",
       "       'faceAttributes.occlusion.eyeOccluded',\n",
       "       'faceAttributes.occlusion.mouthOccluded', 'faceAttributes.hair.bald',\n",
       "       'faceAttributes.hair.invisible', 'faceAttributes.hair.hairColor'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceId</th>\n",
       "      <th>faceAttributes.glasses</th>\n",
       "      <th>faceAttributes.emotion.neutral</th>\n",
       "      <th>faceAttributes.age</th>\n",
       "      <th>faceAttributes.gender</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>117c7959-4749-4edc-a730-8b02c0601d30</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.184</td>\n",
       "      <td>18.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6bed9231-c27b-4f46-be23-6f298235f525</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.542</td>\n",
       "      <td>20.0</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8693aea4-c385-499a-89e2-2d19a0c30a23</td>\n",
       "      <td>ReadingGlasses</td>\n",
       "      <td>0.000</td>\n",
       "      <td>23.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>de8d7f6a-6b67-4a66-bc7c-ae6de435b612</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.000</td>\n",
       "      <td>21.0</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2bffa3fd-ecf6-4dcc-8686-23301e0508b6</td>\n",
       "      <td>ReadingGlasses</td>\n",
       "      <td>0.019</td>\n",
       "      <td>17.0</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>b5a606b9-82dd-40b0-9180-cc7c36b0d575</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.000</td>\n",
       "      <td>19.0</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 faceId faceAttributes.glasses  \\\n",
       "0  117c7959-4749-4edc-a730-8b02c0601d30              NoGlasses   \n",
       "1  6bed9231-c27b-4f46-be23-6f298235f525              NoGlasses   \n",
       "2  8693aea4-c385-499a-89e2-2d19a0c30a23         ReadingGlasses   \n",
       "3  de8d7f6a-6b67-4a66-bc7c-ae6de435b612              NoGlasses   \n",
       "4  2bffa3fd-ecf6-4dcc-8686-23301e0508b6         ReadingGlasses   \n",
       "5  b5a606b9-82dd-40b0-9180-cc7c36b0d575              NoGlasses   \n",
       "\n",
       "   faceAttributes.emotion.neutral  faceAttributes.age faceAttributes.gender  \n",
       "0                           0.184                18.0                  male  \n",
       "1                           0.542                20.0                female  \n",
       "2                           0.000                23.0                  male  \n",
       "3                           0.000                21.0                female  \n",
       "4                           0.019                17.0                female  \n",
       "5                           0.000                19.0                female  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可观察其中指数\n",
    "df[['faceId','faceAttributes.glasses','faceAttributes.emotion.neutral','faceAttributes.age','faceAttributes.gender']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 试一试：人脸验证(难)\n",
    "\n",
    "人脸相似度？有没有试下？\n",
    "\n",
    "* API人脸文档中最重要的组成部分：\n",
    "   \n",
    "    * Request URL？\n",
    "    * Http Method？\n",
    "    * 参数？\n",
    "\n",
    "----\n",
    "* 不同的人脸对比数据\n",
    "    * 人脸验证关键数据？\n",
    "    * 根据哪些数据证明是同一个人？\n",
    "    \n",
    "----\n",
    "* 具体步骤：\n",
    "    * 1、Create 请求成功200 返回空字符串\n",
    "    * 2、Add face 请求成功200 返回persistedFaceId\n",
    "    * 3、Detect 准备 被检测人 人脸的id\n",
    "    * 4、Find similars 返回相似置信度\n",
    "    * 附加：get查看facelists\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1、create\n",
    "create_facelists_url = \"https://westcentralus.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}\" \n",
    "subscription_key = \"aae352f75f71488983b4031443382905\"\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "data = {\n",
    "    \"name\": \"list-zzx\",\n",
    "    \"userData\": \"zzx\",\n",
    "    \"recognitionModel\": \"recognition_02\"\n",
    "}\n",
    "params = {\n",
    "    # Request parameters    \n",
    "   \n",
    "    \"faceListId\":\"zzx\"\n",
    "    \n",
    "#     'detectionModel': 'detection_01',\n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url,headers=headers,params=params,json=data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 请求成功，返回空字符串\n",
    "r_create.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2、Add face\n",
    "add_face_url =\"https://westcentralus.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}/persistedFaces\"\n",
    "subscription_key = \"29153ccda10844dfa502a054e03cdd54\"\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"https://img5.iqiyipic.com/image/feigesmp/feigesmp_5e266d750adcdc72bb37e1b9_default.jpg\"\n",
    "\n",
    "params_add_face={\n",
    "    \"faceListId\":\"zzx\",\n",
    "    \"userData\":\"吴亦凡\"\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url,headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "# r = requests.post(add_face, headers=headers,params = params,json={\"url\": add_face_image})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://westcentralus.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}/persistedFaces\"\n",
    "    subscription_key = \"aae352f75f71488983b4031443382905\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"faceListId\":\"ywy\",\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url,headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 顺便把查看列表的也给封装了\n",
    "# Get facelist\n",
    "def GetFacelist():\n",
    "    get_facelist_url = \"https://westcentralus.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}\"\n",
    "    data = {\n",
    "        \"faceListId\":\"ywy\",\n",
    "    }\n",
    "    r_get_facelist = requests.get(get_facelist_url,headers=headers,params=data)\n",
    "    return r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': 'df20b22c-ad0c-454f-8b37-06c50690f481',\n",
       "   'userData': '喻言'},\n",
       "  {'persistedFaceId': 'bd12bee0-b4ea-4f50-b106-52d04e9a333f',\n",
       "   'userData': '安崎'},\n",
       "  {'persistedFaceId': 'c6a4f418-ab34-4321-ad00-e1ec6097573c',\n",
       "   'userData': '蔡卓宜'},\n",
       "  {'persistedFaceId': 'd4be10ff-adf6-4a65-8e9e-276599e62b25',\n",
       "   'userData': '陈品瑄'},\n",
       "  {'persistedFaceId': '4be383f6-e84d-4afa-8883-d65049d78bbb',\n",
       "   'userData': '陈珏'},\n",
       "  {'persistedFaceId': '52cdc6ff-ba05-4890-90fa-f3a247307634',\n",
       "   'userData': '陈昕崴'},\n",
       "  {'persistedFaceId': '159bc0dd-3d1b-423b-a29b-856853b9b390',\n",
       "   'userData': '戴萌'},\n",
       "  {'persistedFaceId': '32df08c9-ce98-478f-9196-e89bab589d24',\n",
       "   'userData': '戴燕妮'},\n",
       "  {'persistedFaceId': 'ddc27dbe-ff8d-48ab-9cb5-a59d9f148a21',\n",
       "   'userData': '段小薇'},\n",
       "  {'persistedFaceId': 'b467c71a-fcda-4fc0-b122-c1086a171150',\n",
       "   'userData': '段艺璇'},\n",
       "  {'persistedFaceId': '47678aaa-6425-48ec-9753-96c9db6b4a40',\n",
       "   'userData': '费沁源'},\n",
       "  {'persistedFaceId': 'c20c53ce-cf5f-4f54-9b93-ad7a7e184303',\n",
       "   'userData': '傅如乔'},\n",
       "  {'persistedFaceId': '2312d631-1d03-4f53-ab1a-4af20023f369',\n",
       "   'userData': '葛鑫怡'},\n",
       "  {'persistedFaceId': '328f5098-7308-4732-bcd5-058ce28f98fe',\n",
       "   'userData': '勾雪莹'},\n",
       "  {'persistedFaceId': 'db1320ae-a3be-47c0-8f54-0c52348302d3',\n",
       "   'userData': '冯若航'},\n",
       "  {'persistedFaceId': '3eb039ab-99c1-4828-b96f-6dbbdfebf0df',\n",
       "   'userData': '符雅凝'},\n",
       "  {'persistedFaceId': 'eb314668-5572-45f7-b8ec-9022c25b1112',\n",
       "   'userData': '韩东'},\n",
       "  {'persistedFaceId': '34b73d9f-9ed7-4f7c-8ed2-e70954df97f0',\n",
       "   'userData': '胡馨尹'},\n",
       "  {'persistedFaceId': '00aefd02-ccfd-4766-afa2-36e7685c4e48',\n",
       "   'userData': '黄欣苑'},\n",
       "  {'persistedFaceId': 'd2022f68-6c7d-48eb-92aa-00daa567a352',\n",
       "   'userData': '靳阳阳'},\n",
       "  {'persistedFaceId': '46d05097-b1b1-41d5-915b-398f6fd94501',\n",
       "   'userData': '金子涵'},\n",
       "  {'persistedFaceId': '106c74c6-47a1-4059-8c5f-dbb80d8ff11e',\n",
       "   'userData': '孔雪儿'},\n",
       "  {'persistedFaceId': '944a755c-1220-4fdf-ae9c-20da454a6de5',\n",
       "   'userData': '李依宸'},\n",
       "  {'persistedFaceId': 'a380f297-4792-4683-8ebd-0586020ee709',\n",
       "   'userData': '林凡'},\n",
       "  {'persistedFaceId': 'eb553bae-ae88-477e-b3de-840780257e18',\n",
       "   'userData': '林小宅'},\n",
       "  {'persistedFaceId': '8b24bfaa-a0c8-421c-b320-c8e99dacf1ed',\n",
       "   'userData': '刘令姿'},\n",
       "  {'persistedFaceId': '58078d82-86f3-4c39-9e56-a3d92700697a',\n",
       "   'userData': '刘雨昕'},\n",
       "  {'persistedFaceId': '357dd4f3-2d27-45e6-a891-af83e5780da0',\n",
       "   'userData': '陆柯燃'},\n",
       "  {'persistedFaceId': '66bfa2c0-e9bc-4f5d-81bb-2cf97d049a14',\n",
       "   'userData': '马蜀君'},\n",
       "  {'persistedFaceId': '2a0a4645-d019-4438-92c1-5739ad046e3e',\n",
       "   'userData': '莫寒'},\n",
       "  {'persistedFaceId': 'cd25aac5-ecb4-49b9-82a3-0150fbc79c59',\n",
       "   'userData': '乃万'},\n",
       "  {'persistedFaceId': 'a630880a-4a55-49b6-8421-1f8b422ea581',\n",
       "   'userData': '七穗'},\n",
       "  {'persistedFaceId': '47c09bca-7dda-46ac-b493-b0d436df6604',\n",
       "   'userData': '秦牛正威'},\n",
       "  {'persistedFaceId': '7e6f42e3-3d2f-4be3-a245-cc74335c6bee',\n",
       "   'userData': '上官喜爱'},\n",
       "  {'persistedFaceId': '6bea080c-16d5-44a8-9148-819533c2ec3b',\n",
       "   'userData': '宋昕冉'},\n",
       "  {'persistedFaceId': 'e6183244-db45-4539-b74d-243d8fee4111',\n",
       "   'userData': '宋昭艺'},\n",
       "  {'persistedFaceId': 'eab1e013-d6e0-45a0-a488-adbf870d4e88',\n",
       "   'userData': '苏杉杉'},\n",
       "  {'persistedFaceId': '53edbc19-315b-4e44-9625-6b45030ea3e7',\n",
       "   'userData': '孙美楠'},\n",
       "  {'persistedFaceId': '38d7a236-bda8-48f7-8405-242affd7f3f5',\n",
       "   'userData': '孙芮'},\n",
       "  {'persistedFaceId': 'f34501c9-8d45-4f60-92e6-fdd81a75353b',\n",
       "   'userData': '王承渲'},\n",
       "  {'persistedFaceId': 'ce71620e-061f-4ac7-94b8-c99147d29ab2',\n",
       "   'userData': '王清'},\n",
       "  {'persistedFaceId': 'b0c2d70c-1ea2-425c-9337-0b1c58cd8b44',\n",
       "   'userData': '王婉辰'},\n",
       "  {'persistedFaceId': 'ea0f0722-7d68-463f-b3d8-5bf55ae03ad8',\n",
       "   'userData': '王欣宇'},\n",
       "  {'persistedFaceId': '379376de-116f-4210-8de6-2bd22b1bf465',\n",
       "   'userData': '魏辰'},\n",
       "  {'persistedFaceId': '880e7c8b-3d73-4f7f-9432-a69a7b20a234',\n",
       "   'userData': '夏研'},\n",
       "  {'persistedFaceId': '99680299-fa88-48a9-83fc-41fae7128a1e',\n",
       "   'userData': '谢可寅'},\n",
       "  {'persistedFaceId': 'e9948fc2-2c12-4904-968e-c536db2d38ec',\n",
       "   'userData': '许佳琪'},\n",
       "  {'persistedFaceId': '9a44b280-fbc6-4a24-8959-e85a49f09206',\n",
       "   'userData': '许馨文'},\n",
       "  {'persistedFaceId': '89eb009d-6cd1-4e57-9dff-42781a06a6d3',\n",
       "   'userData': '许杨玉琢'},\n",
       "  {'persistedFaceId': '43a5fcfd-86d5-4a51-9735-847d8e2fe744',\n",
       "   'userData': '徐轸轸'},\n",
       "  {'persistedFaceId': '50300483-2867-4dd5-9aec-7261e3660ab3',\n",
       "   'userData': '徐紫茵'},\n",
       "  {'persistedFaceId': 'b33f7aee-bd89-42a2-82ef-2e384234aca5',\n",
       "   'userData': '虞书欣'},\n",
       "  {'persistedFaceId': '483c0dbc-e23b-414f-9849-8047397440c5',\n",
       "   'userData': '曾可妮'},\n",
       "  {'persistedFaceId': '8f5272a1-bb86-450d-b844-7f29eee7f42b',\n",
       "   'userData': '张楚寒'},\n",
       "  {'persistedFaceId': '8f93077b-2876-46c5-9abb-446caf46da75',\n",
       "   'userData': '张梦露'},\n",
       "  {'persistedFaceId': '3c730dcb-72c5-463b-b788-1e0f8e9a928e',\n",
       "   'userData': '张钰'},\n",
       "  {'persistedFaceId': '8a1ef233-c70d-40d1-b4b6-deb115cda395',\n",
       "   'userData': '张语格'},\n",
       "  {'persistedFaceId': 'd010c419-74cc-4129-989c-718f7dfa3cde',\n",
       "   'userData': '赵小棠'},\n",
       "  {'persistedFaceId': 'b6244fca-937a-4065-a35d-f2c17a8225b2',\n",
       "   'userData': '朱林雨'},\n",
       "  {'persistedFaceId': '9456b07a-eb8f-463f-91c5-383bf01061a5',\n",
       "   'userData': '左卓'},\n",
       "  {'persistedFaceId': '8aaf0f83-9f3c-44dd-b903-f007934d6173',\n",
       "   'userData': '喻言'},\n",
       "  {'persistedFaceId': 'f8c1183f-4cea-45c9-a778-a50ba825587e',\n",
       "   'userData': '赵小棠'},\n",
       "  {'persistedFaceId': '2d29b2b8-9f9f-4940-b687-f850022d3df8',\n",
       "   'userData': '朱林雨'},\n",
       "  {'persistedFaceId': '60559787-1d4a-49f4-9af9-a84e3e82fcdc',\n",
       "   'userData': '左卓'},\n",
       "  {'persistedFaceId': 'ecb10a2c-880b-47fc-9d2a-9c4a160f7408',\n",
       "   'userData': '喻言'}],\n",
       " 'faceListId': 'ywy',\n",
       " 'name': 'list_week03',\n",
       " 'userData': 'youth with you'}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GetFacelist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://img5.iqiyipic.com/image/feigesmp/feigesmp_5e266cab2455d79407d7e481_default.jpg\",\"赵小棠\")\n",
    "AddFace(\"https://img5.iqiyipic.com/image/feigesmp/feigesmp_5e2668e00adcdc9812ba500f_default.jpg\",\"朱林雨\")\n",
    "AddFace(\"https://img5.iqiyipic.com/image/feigesmp/feigesmp_5e266d212455d79407d7e5cd_default.jpg\",\"左卓\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"persistedFaceId\":\"8aaf0f83-9f3c-44dd-b903-f007934d6173\"}'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'[{\"faceId\": \"76ec16f5-cf65-4d6e-9bec-7ac8b1f19204\", \"faceRectangle\": {\"top\": 323, \"left\": 161, \"width\": 437, \"height\": 437}, \"faceAttributes\": {\"smile\": 0.993, \"headPose\": {\"pitch\": -5.6, \"roll\": 3.7, \"yaw\": 8.3}, \"gender\": \"female\", \"age\": 17.0, \"facialHair\": {\"moustache\": 0.0, \"beard\": 0.0, \"sideburns\": 0.0}, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 0.993, \"neutral\": 0.007, \"sadness\": 0.0, \"surprise\": 0.0}, \"blur\": {\"blurLevel\": \"medium\", \"value\": 0.45}, \"exposure\": {\"exposureLevel\": \"goodExposure\", \"value\": 0.6}, \"noise\": {\"noiseLevel\": \"medium\", \"value\": 0.32}, \"makeup\": {\"eyeMakeup\": true, \"lipMakeup\": true}, \"accessories\": [], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.04, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 0.98}, {\"color\": \"brown\", \"confidence\": 0.97}, {\"color\": \"gray\", \"confidence\": 0.64}, {\"color\": \"other\", \"confidence\": 0.12}, {\"color\": \"blond\", \"confidence\": 0.11}, {\"color\": \"red\", \"confidence\": 0.02}]}}}]'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、检测人脸的id\n",
    "\n",
    "\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'https://images.gitee.com/uploads/images/2020/0415/235712_d818dbd3_4875323.png'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_02',\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "json.dumps(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "我的脸 = response.json()[0][\"faceId\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "#4、Find similars\n",
    "\n",
    "findsimilars_url = \"https://westcentralus.api.cognitive.microsoft.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":我的脸,\n",
    "    \"faceListId\":\"ywy\",\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\"\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'[{\"persistedFaceId\":\"ce71620e-061f-4ac7-94b8-c99147d29ab2\",\"confidence\":0.4135},{\"persistedFaceId\":\"47678aaa-6425-48ec-9753-96c9db6b4a40\",\"confidence\":0.3971},{\"persistedFaceId\":\"58078d82-86f3-4c39-9e56-a3d92700697a\",\"confidence\":0.33768},{\"persistedFaceId\":\"eb553bae-ae88-477e-b3de-840780257e18\",\"confidence\":0.27396},{\"persistedFaceId\":\"8a1ef233-c70d-40d1-b4b6-deb115cda395\",\"confidence\":0.26495},{\"persistedFaceId\":\"ddc27dbe-ff8d-48ab-9cb5-a59d9f148a21\",\"confidence\":0.23472},{\"persistedFaceId\":\"2312d631-1d03-4f53-ab1a-4af20023f369\",\"confidence\":0.21798},{\"persistedFaceId\":\"34b73d9f-9ed7-4f7c-8ed2-e70954df97f0\",\"confidence\":0.17447},{\"persistedFaceId\":\"483c0dbc-e23b-414f-9849-8047397440c5\",\"confidence\":0.17138},{\"persistedFaceId\":\"9a44b280-fbc6-4a24-8959-e85a49f09206\",\"confidence\":0.16966}]'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.content"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 将人脸数据库做成表格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>df20b22c-ad0c-454f-8b37-06c50690f481</td>\n",
       "      <td>喻言</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bd12bee0-b4ea-4f50-b106-52d04e9a333f</td>\n",
       "      <td>安崎</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>c6a4f418-ab34-4321-ad00-e1ec6097573c</td>\n",
       "      <td>蔡卓宜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>d4be10ff-adf6-4a65-8e9e-276599e62b25</td>\n",
       "      <td>陈品瑄</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4be383f6-e84d-4afa-8883-d65049d78bbb</td>\n",
       "      <td>陈珏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>60559787-1d4a-49f4-9af9-a84e3e82fcdc</td>\n",
       "      <td>左卓</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>ecb10a2c-880b-47fc-9d2a-9c4a160f7408</td>\n",
       "      <td>喻言</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>24cf001b-fc7d-4a8e-9fe1-9140b92cf84e</td>\n",
       "      <td>赵小棠</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>52f39362-635d-43d0-833f-c7362d5bca26</td>\n",
       "      <td>朱林雨</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>f73d598b-f3c0-4d97-b5c2-7490fbae532e</td>\n",
       "      <td>左卓</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                         persistedFaceId userData\n",
       "0   df20b22c-ad0c-454f-8b37-06c50690f481       喻言\n",
       "1   bd12bee0-b4ea-4f50-b106-52d04e9a333f       安崎\n",
       "2   c6a4f418-ab34-4321-ad00-e1ec6097573c      蔡卓宜\n",
       "3   d4be10ff-adf6-4a65-8e9e-276599e62b25      陈品瑄\n",
       "4   4be383f6-e84d-4afa-8883-d65049d78bbb       陈珏\n",
       "..                                   ...      ...\n",
       "63  60559787-1d4a-49f4-9af9-a84e3e82fcdc       左卓\n",
       "64  ecb10a2c-880b-47fc-9d2a-9c4a160f7408       喻言\n",
       "65  24cf001b-fc7d-4a8e-9fe1-9140b92cf84e      赵小棠\n",
       "66  52f39362-635d-43d0-833f-c7362d5bca26      朱林雨\n",
       "67  f73d598b-f3c0-4d97-b5c2-7490fbae532e       左卓\n",
       "\n",
       "[68 rows x 2 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_facelist_url = \"https://westcentralus.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}\"\n",
    "\n",
    "data = {\n",
    "    \"faceListId\":\"ywy\",\n",
    "\n",
    "}\n",
    "\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers,params=data)\n",
    "r_get_facelist.json()\n",
    "adf = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])# 升级pandas才能运行\n",
    "adf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ce71620e-061f-4ac7-94b8-c99147d29ab2</td>\n",
       "      <td>0.41350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>47678aaa-6425-48ec-9753-96c9db6b4a40</td>\n",
       "      <td>0.39710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>58078d82-86f3-4c39-9e56-a3d92700697a</td>\n",
       "      <td>0.33768</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>eb553bae-ae88-477e-b3de-840780257e18</td>\n",
       "      <td>0.27396</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8a1ef233-c70d-40d1-b4b6-deb115cda395</td>\n",
       "      <td>0.26495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ddc27dbe-ff8d-48ab-9cb5-a59d9f148a21</td>\n",
       "      <td>0.23472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2312d631-1d03-4f53-ab1a-4af20023f369</td>\n",
       "      <td>0.21798</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>34b73d9f-9ed7-4f7c-8ed2-e70954df97f0</td>\n",
       "      <td>0.17447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>483c0dbc-e23b-414f-9849-8047397440c5</td>\n",
       "      <td>0.17138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9a44b280-fbc6-4a24-8959-e85a49f09206</td>\n",
       "      <td>0.16966</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  ce71620e-061f-4ac7-94b8-c99147d29ab2     0.41350\n",
       "1  47678aaa-6425-48ec-9753-96c9db6b4a40     0.39710\n",
       "2  58078d82-86f3-4c39-9e56-a3d92700697a     0.33768\n",
       "3  eb553bae-ae88-477e-b3de-840780257e18     0.27396\n",
       "4  8a1ef233-c70d-40d1-b4b6-deb115cda395     0.26495\n",
       "5  ddc27dbe-ff8d-48ab-9cb5-a59d9f148a21     0.23472\n",
       "6  2312d631-1d03-4f53-ab1a-4af20023f369     0.21798\n",
       "7  34b73d9f-9ed7-4f7c-8ed2-e70954df97f0     0.17447\n",
       "8  483c0dbc-e23b-414f-9849-8047397440c5     0.17138\n",
       "9  9a44b280-fbc6-4a24-8959-e85a49f09206     0.16966"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdf = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "bdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>ce71620e-061f-4ac7-94b8-c99147d29ab2</td>\n",
       "      <td>王清</td>\n",
       "      <td>0.41350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>47678aaa-6425-48ec-9753-96c9db6b4a40</td>\n",
       "      <td>费沁源</td>\n",
       "      <td>0.39710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>58078d82-86f3-4c39-9e56-a3d92700697a</td>\n",
       "      <td>刘雨昕</td>\n",
       "      <td>0.33768</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>eb553bae-ae88-477e-b3de-840780257e18</td>\n",
       "      <td>林小宅</td>\n",
       "      <td>0.27396</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>8a1ef233-c70d-40d1-b4b6-deb115cda395</td>\n",
       "      <td>张语格</td>\n",
       "      <td>0.26495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ddc27dbe-ff8d-48ab-9cb5-a59d9f148a21</td>\n",
       "      <td>段小薇</td>\n",
       "      <td>0.23472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2312d631-1d03-4f53-ab1a-4af20023f369</td>\n",
       "      <td>葛鑫怡</td>\n",
       "      <td>0.21798</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>34b73d9f-9ed7-4f7c-8ed2-e70954df97f0</td>\n",
       "      <td>胡馨尹</td>\n",
       "      <td>0.17447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>483c0dbc-e23b-414f-9849-8047397440c5</td>\n",
       "      <td>曾可妮</td>\n",
       "      <td>0.17138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>9a44b280-fbc6-4a24-8959-e85a49f09206</td>\n",
       "      <td>许馨文</td>\n",
       "      <td>0.16966</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId userData  confidence\n",
       "6  ce71620e-061f-4ac7-94b8-c99147d29ab2       王清     0.41350\n",
       "1  47678aaa-6425-48ec-9753-96c9db6b4a40      费沁源     0.39710\n",
       "5  58078d82-86f3-4c39-9e56-a3d92700697a      刘雨昕     0.33768\n",
       "4  eb553bae-ae88-477e-b3de-840780257e18      林小宅     0.27396\n",
       "9  8a1ef233-c70d-40d1-b4b6-deb115cda395      张语格     0.26495\n",
       "0  ddc27dbe-ff8d-48ab-9cb5-a59d9f148a21      段小薇     0.23472\n",
       "2  2312d631-1d03-4f53-ab1a-4af20023f369      葛鑫怡     0.21798\n",
       "3  34b73d9f-9ed7-4f7c-8ed2-e70954df97f0      胡馨尹     0.17447\n",
       "8  483c0dbc-e23b-414f-9849-8047397440c5      曾可妮     0.17138\n",
       "7  9a44b280-fbc6-4a24-8959-e85a49f09206      许馨文     0.16966"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(adf, bdf,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get facelist\n",
    "get_facelist_url = \"https://westcentralus.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}\"\n",
    "\n",
    "data = {\n",
    "    \"faceListId\":\"ywy\",\n",
    "\n",
    "}\n",
    "\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers,params=data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_get_facelist.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"persistedFaces\":[{\"persistedFaceId\":\"df20b22c-ad0c-454f-8b37-06c50690f481\",\"userData\":\"\\xe5\\x96\\xbb\\xe8\\xa8\\x80\"},{\"persistedFaceId\":\"bd12bee0-b4ea-4f50-b106-52d04e9a333f\",\"userData\":\"\\xe5\\xae\\x89\\xe5\\xb4\\x8e\"},{\"persistedFaceId\":\"c6a4f418-ab34-4321-ad00-e1ec6097573c\",\"userData\":\"\\xe8\\x94\\xa1\\xe5\\x8d\\x93\\xe5\\xae\\x9c\"},{\"persistedFaceId\":\"d4be10ff-adf6-4a65-8e9e-276599e62b25\",\"userData\":\"\\xe9\\x99\\x88\\xe5\\x93\\x81\\xe7\\x91\\x84\"},{\"persistedFaceId\":\"4be383f6-e84d-4afa-8883-d65049d78bbb\",\"userData\":\"\\xe9\\x99\\x88\\xe7\\x8f\\x8f\"},{\"persistedFaceId\":\"52cdc6ff-ba05-4890-90fa-f3a247307634\",\"userData\":\"\\xe9\\x99\\x88\\xe6\\x98\\x95\\xe5\\xb4\\xb4\"},{\"persistedFaceId\":\"159bc0dd-3d1b-423b-a29b-856853b9b390\",\"userData\":\"\\xe6\\x88\\xb4\\xe8\\x90\\x8c\"},{\"persistedFaceId\":\"32df08c9-ce98-478f-9196-e89bab589d24\",\"userData\":\"\\xe6\\x88\\xb4\\xe7\\x87\\x95\\xe5\\xa6\\xae\"},{\"persistedFaceId\":\"ddc27dbe-ff8d-48ab-9cb5-a59d9f148a21\",\"userData\":\"\\xe6\\xae\\xb5\\xe5\\xb0\\x8f\\xe8\\x96\\x87\"},{\"persistedFaceId\":\"b467c71a-fcda-4fc0-b122-c1086a171150\",\"userData\":\"\\xe6\\xae\\xb5\\xe8\\x89\\xba\\xe7\\x92\\x87\"},{\"persistedFaceId\":\"47678aaa-6425-48ec-9753-96c9db6b4a40\",\"userData\":\"\\xe8\\xb4\\xb9\\xe6\\xb2\\x81\\xe6\\xba\\x90\"},{\"persistedFaceId\":\"c20c53ce-cf5f-4f54-9b93-ad7a7e184303\",\"userData\":\"\\xe5\\x82\\x85\\xe5\\xa6\\x82\\xe4\\xb9\\x94\"},{\"persistedFaceId\":\"2312d631-1d03-4f53-ab1a-4af20023f369\",\"userData\":\"\\xe8\\x91\\x9b\\xe9\\x91\\xab\\xe6\\x80\\xa1\"},{\"persistedFaceId\":\"328f5098-7308-4732-bcd5-058ce28f98fe\",\"userData\":\"\\xe5\\x8b\\xbe\\xe9\\x9b\\xaa\\xe8\\x8e\\xb9\"},{\"persistedFaceId\":\"db1320ae-a3be-47c0-8f54-0c52348302d3\",\"userData\":\"\\xe5\\x86\\xaf\\xe8\\x8b\\xa5\\xe8\\x88\\xaa\"},{\"persistedFaceId\":\"3eb039ab-99c1-4828-b96f-6dbbdfebf0df\",\"userData\":\"\\xe7\\xac\\xa6\\xe9\\x9b\\x85\\xe5\\x87\\x9d\"},{\"persistedFaceId\":\"eb314668-5572-45f7-b8ec-9022c25b1112\",\"userData\":\"\\xe9\\x9f\\xa9\\xe4\\xb8\\x9c\"},{\"persistedFaceId\":\"34b73d9f-9ed7-4f7c-8ed2-e70954df97f0\",\"userData\":\"\\xe8\\x83\\xa1\\xe9\\xa6\\xa8\\xe5\\xb0\\xb9\"},{\"persistedFaceId\":\"00aefd02-ccfd-4766-afa2-36e7685c4e48\",\"userData\":\"\\xe9\\xbb\\x84\\xe6\\xac\\xa3\\xe8\\x8b\\x91\"},{\"persistedFaceId\":\"d2022f68-6c7d-48eb-92aa-00daa567a352\",\"userData\":\"\\xe9\\x9d\\xb3\\xe9\\x98\\xb3\\xe9\\x98\\xb3\"},{\"persistedFaceId\":\"46d05097-b1b1-41d5-915b-398f6fd94501\",\"userData\":\"\\xe9\\x87\\x91\\xe5\\xad\\x90\\xe6\\xb6\\xb5\"},{\"persistedFaceId\":\"106c74c6-47a1-4059-8c5f-dbb80d8ff11e\",\"userData\":\"\\xe5\\xad\\x94\\xe9\\x9b\\xaa\\xe5\\x84\\xbf\"},{\"persistedFaceId\":\"944a755c-1220-4fdf-ae9c-20da454a6de5\",\"userData\":\"\\xe6\\x9d\\x8e\\xe4\\xbe\\x9d\\xe5\\xae\\xb8\"},{\"persistedFaceId\":\"a380f297-4792-4683-8ebd-0586020ee709\",\"userData\":\"\\xe6\\x9e\\x97\\xe5\\x87\\xa1\"},{\"persistedFaceId\":\"eb553bae-ae88-477e-b3de-840780257e18\",\"userData\":\"\\xe6\\x9e\\x97\\xe5\\xb0\\x8f\\xe5\\xae\\x85\"},{\"persistedFaceId\":\"8b24bfaa-a0c8-421c-b320-c8e99dacf1ed\",\"userData\":\"\\xe5\\x88\\x98\\xe4\\xbb\\xa4\\xe5\\xa7\\xbf\"},{\"persistedFaceId\":\"58078d82-86f3-4c39-9e56-a3d92700697a\",\"userData\":\"\\xe5\\x88\\x98\\xe9\\x9b\\xa8\\xe6\\x98\\x95\"},{\"persistedFaceId\":\"357dd4f3-2d27-45e6-a891-af83e5780da0\",\"userData\":\"\\xe9\\x99\\x86\\xe6\\x9f\\xaf\\xe7\\x87\\x83\"},{\"persistedFaceId\":\"66bfa2c0-e9bc-4f5d-81bb-2cf97d049a14\",\"userData\":\"\\xe9\\xa9\\xac\\xe8\\x9c\\x80\\xe5\\x90\\x9b\"},{\"persistedFaceId\":\"2a0a4645-d019-4438-92c1-5739ad046e3e\",\"userData\":\"\\xe8\\x8e\\xab\\xe5\\xaf\\x92\"},{\"persistedFaceId\":\"cd25aac5-ecb4-49b9-82a3-0150fbc79c59\",\"userData\":\"\\xe4\\xb9\\x83\\xe4\\xb8\\x87\"},{\"persistedFaceId\":\"a630880a-4a55-49b6-8421-1f8b422ea581\",\"userData\":\"\\xe4\\xb8\\x83\\xe7\\xa9\\x97\"},{\"persistedFaceId\":\"47c09bca-7dda-46ac-b493-b0d436df6604\",\"userData\":\"\\xe7\\xa7\\xa6\\xe7\\x89\\x9b\\xe6\\xad\\xa3\\xe5\\xa8\\x81\"},{\"persistedFaceId\":\"7e6f42e3-3d2f-4be3-a245-cc74335c6bee\",\"userData\":\"\\xe4\\xb8\\x8a\\xe5\\xae\\x98\\xe5\\x96\\x9c\\xe7\\x88\\xb1\"},{\"persistedFaceId\":\"6bea080c-16d5-44a8-9148-819533c2ec3b\",\"userData\":\"\\xe5\\xae\\x8b\\xe6\\x98\\x95\\xe5\\x86\\x89\"},{\"persistedFaceId\":\"e6183244-db45-4539-b74d-243d8fee4111\",\"userData\":\"\\xe5\\xae\\x8b\\xe6\\x98\\xad\\xe8\\x89\\xba\"},{\"persistedFaceId\":\"eab1e013-d6e0-45a0-a488-adbf870d4e88\",\"userData\":\"\\xe8\\x8b\\x8f\\xe6\\x9d\\x89\\xe6\\x9d\\x89\"},{\"persistedFaceId\":\"53edbc19-315b-4e44-9625-6b45030ea3e7\",\"userData\":\"\\xe5\\xad\\x99\\xe7\\xbe\\x8e\\xe6\\xa5\\xa0\"},{\"persistedFaceId\":\"38d7a236-bda8-48f7-8405-242affd7f3f5\",\"userData\":\"\\xe5\\xad\\x99\\xe8\\x8a\\xae\"},{\"persistedFaceId\":\"f34501c9-8d45-4f60-92e6-fdd81a75353b\",\"userData\":\"\\xe7\\x8e\\x8b\\xe6\\x89\\xbf\\xe6\\xb8\\xb2\"},{\"persistedFaceId\":\"ce71620e-061f-4ac7-94b8-c99147d29ab2\",\"userData\":\"\\xe7\\x8e\\x8b\\xe6\\xb8\\x85\"},{\"persistedFaceId\":\"b0c2d70c-1ea2-425c-9337-0b1c58cd8b44\",\"userData\":\"\\xe7\\x8e\\x8b\\xe5\\xa9\\x89\\xe8\\xbe\\xb0\"},{\"persistedFaceId\":\"ea0f0722-7d68-463f-b3d8-5bf55ae03ad8\",\"userData\":\"\\xe7\\x8e\\x8b\\xe6\\xac\\xa3\\xe5\\xae\\x87\"},{\"persistedFaceId\":\"379376de-116f-4210-8de6-2bd22b1bf465\",\"userData\":\"\\xe9\\xad\\x8f\\xe8\\xbe\\xb0\"},{\"persistedFaceId\":\"880e7c8b-3d73-4f7f-9432-a69a7b20a234\",\"userData\":\"\\xe5\\xa4\\x8f\\xe7\\xa0\\x94\"},{\"persistedFaceId\":\"99680299-fa88-48a9-83fc-41fae7128a1e\",\"userData\":\"\\xe8\\xb0\\xa2\\xe5\\x8f\\xaf\\xe5\\xaf\\x85\"},{\"persistedFaceId\":\"e9948fc2-2c12-4904-968e-c536db2d38ec\",\"userData\":\"\\xe8\\xae\\xb8\\xe4\\xbd\\xb3\\xe7\\x90\\xaa\"},{\"persistedFaceId\":\"9a44b280-fbc6-4a24-8959-e85a49f09206\",\"userData\":\"\\xe8\\xae\\xb8\\xe9\\xa6\\xa8\\xe6\\x96\\x87\"},{\"persistedFaceId\":\"89eb009d-6cd1-4e57-9dff-42781a06a6d3\",\"userData\":\"\\xe8\\xae\\xb8\\xe6\\x9d\\xa8\\xe7\\x8e\\x89\\xe7\\x90\\xa2\"},{\"persistedFaceId\":\"43a5fcfd-86d5-4a51-9735-847d8e2fe744\",\"userData\":\"\\xe5\\xbe\\x90\\xe8\\xbd\\xb8\\xe8\\xbd\\xb8\"},{\"persistedFaceId\":\"50300483-2867-4dd5-9aec-7261e3660ab3\",\"userData\":\"\\xe5\\xbe\\x90\\xe7\\xb4\\xab\\xe8\\x8c\\xb5\"},{\"persistedFaceId\":\"b33f7aee-bd89-42a2-82ef-2e384234aca5\",\"userData\":\"\\xe8\\x99\\x9e\\xe4\\xb9\\xa6\\xe6\\xac\\xa3\"},{\"persistedFaceId\":\"483c0dbc-e23b-414f-9849-8047397440c5\",\"userData\":\"\\xe6\\x9b\\xbe\\xe5\\x8f\\xaf\\xe5\\xa6\\xae\"},{\"persistedFaceId\":\"8f5272a1-bb86-450d-b844-7f29eee7f42b\",\"userData\":\"\\xe5\\xbc\\xa0\\xe6\\xa5\\x9a\\xe5\\xaf\\x92\"},{\"persistedFaceId\":\"8f93077b-2876-46c5-9abb-446caf46da75\",\"userData\":\"\\xe5\\xbc\\xa0\\xe6\\xa2\\xa6\\xe9\\x9c\\xb2\"},{\"persistedFaceId\":\"3c730dcb-72c5-463b-b788-1e0f8e9a928e\",\"userData\":\"\\xe5\\xbc\\xa0\\xe9\\x92\\xb0\"},{\"persistedFaceId\":\"8a1ef233-c70d-40d1-b4b6-deb115cda395\",\"userData\":\"\\xe5\\xbc\\xa0\\xe8\\xaf\\xad\\xe6\\xa0\\xbc\"},{\"persistedFaceId\":\"d010c419-74cc-4129-989c-718f7dfa3cde\",\"userData\":\"\\xe8\\xb5\\xb5\\xe5\\xb0\\x8f\\xe6\\xa3\\xa0\"},{\"persistedFaceId\":\"b6244fca-937a-4065-a35d-f2c17a8225b2\",\"userData\":\"\\xe6\\x9c\\xb1\\xe6\\x9e\\x97\\xe9\\x9b\\xa8\"},{\"persistedFaceId\":\"9456b07a-eb8f-463f-91c5-383bf01061a5\",\"userData\":\"\\xe5\\xb7\\xa6\\xe5\\x8d\\x93\"},{\"persistedFaceId\":\"8aaf0f83-9f3c-44dd-b903-f007934d6173\",\"userData\":\"\\xe5\\x96\\xbb\\xe8\\xa8\\x80\"},{\"persistedFaceId\":\"f8c1183f-4cea-45c9-a778-a50ba825587e\",\"userData\":\"\\xe8\\xb5\\xb5\\xe5\\xb0\\x8f\\xe6\\xa3\\xa0\"},{\"persistedFaceId\":\"2d29b2b8-9f9f-4940-b687-f850022d3df8\",\"userData\":\"\\xe6\\x9c\\xb1\\xe6\\x9e\\x97\\xe9\\x9b\\xa8\"},{\"persistedFaceId\":\"60559787-1d4a-49f4-9af9-a84e3e82fcdc\",\"userData\":\"\\xe5\\xb7\\xa6\\xe5\\x8d\\x93\"}],\"faceListId\":\"ywy\",\"name\":\"list_week03\",\"userData\":\"youth with you\"}'"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_get_facelist.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "327px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
